package com.dg.lecheng.api.user.service;

import com.dg.lecheng.api.user.model.InfoUserRole;
import com.dg.lecheng.api.user.repo.InfoUserRoleDao;
import com.dg.lecheng.base.core.service.CrudService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InfoUserRoleService extends CrudService<InfoUserRoleDao, InfoUserRole, Integer> {
    public int getCount() {
        return curdRepo.getCount();
    }

    public List<InfoUserRole> getByUserId(Integer userId) {
        return curdRepo.getByUserId(userId);
    }

    public void saveOrUpdate(InfoUserRole infoUserRole) {

        InfoUserRole infoUserRoleT = curdRepo.getByUserIdAndRoleId(infoUserRole);
        if(infoUserRoleT==null){
            curdRepo.add(infoUserRole);
        }else{
            infoUserRole.setId(infoUserRoleT.getId());
            curdRepo.update(infoUserRole);
        }
    }

    public void removeByUserId(int userId){
        curdRepo.removeByUserId(userId);
    }

    public void removeByRoleId(int roleId){
        curdRepo.removeByRoleId(roleId);
    }


    public String getRoleName(int userId){
        return curdRepo.getRoleName(userId);
    }
}